import React, { FC } from 'react'
import { useNavigate } from 'react-router-dom';
import { Form, Input, Button, Checkbox } from 'antd';
import { LoginProps } from '@/types/loginTypes'
import { login } from '@/api/login';


const Login: FC = () => {
    const navigate = useNavigate();
    const onFinish = async (values: LoginProps) => {
        const res = await login(values);
        if (res.code === 0) {
            const { token } = res.data;
            localStorage.setItem("mockToken", token);
            navigate('/');
        }
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };
    return (
        <div className='login-container'>
            <div className='title'>
                mock-server
            </div>
            <Form
                name="basic"
                labelCol={{ xs: 6, sm: 6, md: 6, lg: 8, xl: 8, xxl: 9 }}
                wrapperCol={{ xs: 12, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
                size="large"
            >
                <Form.Item
                    label="用户名"
                    name="username"
                    rules={[{ required: true, message: '请输入用户名!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: '请输入密码!' }]}
                >
                    <Input.Password />
                </Form.Item>
                <Form.Item wrapperCol={{ xs: { offset: 6 }, sm: { offset: 6 }, md: { offset: 6 }, lg: { offset: 8 }, xl: { offset: 8 }, xxl: { offset: 9 } }}>
                    <Button type="primary" htmlType="submit">
                        登录
                    </Button>
                </Form.Item>
            </Form>
        </div>
    )
}



export default Login;
